package com.example.administrator.nurse.present;

import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.nurse.R;
import com.example.administrator.nurse.base.BaseActivity;
import com.example.administrator.nurse.model.adapter.CommonAdapter;
import com.example.administrator.nurse.model.adapter.ViewHolder;
import com.example.administrator.nurse.widget.NoScrollGridView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/23.
 */
public class PatientActivity extends BaseActivity {
    ArrayList<String> titleList;
    ArrayList<Integer> imgList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    private void initView(){
        GridView gridView=(NoScrollGridView)findViewById(R.id.execute_control);
        titleList=getTileList();
        imgList=getImgList();
        GridAdapter adapter=new GridAdapter(titleList,R.layout.main_grid_item,PatientActivity.this);
        gridView.setAdapter(adapter);
        configCommonHeader(PatientActivity.this,getResources().getString(R.string.patient_info),0);
    }

    private ArrayList<String> getTileList(){
        ArrayList<String> titleList=new ArrayList<>();
        Resources res=getResources();
        titleList.add(res.getString(R.string.order_title));
        titleList.add(res.getString(R.string.feature_title));
        titleList.add(res.getString(R.string.accouont_title));
        titleList.add(res.getString(R.string.report_title));
        titleList.add(res.getString(R.string.assessment_title));
        titleList.add("");
        return titleList;
    }

    private ArrayList<Integer> getImgList(){
        ArrayList<Integer> imgList=new ArrayList<>();
        imgList.add(R.mipmap.execution_of_doctors_order);
        imgList.add(R.mipmap.sign_entry);
        imgList.add(R.mipmap.search_cost);
        imgList.add(R.mipmap.medical_examination_report);
        imgList.add(R.mipmap.nursing_assessment);
        imgList.add(R.mipmap.others);
        return imgList;
    }

    @Override
    protected int setLayotId() {
        return R.layout.patient_layout;
    }

    @Override
    protected void onFailure(int requestCode, Object object, String errorMsg) {

    }

    @Override
    protected void onSuccess(int requestCode, Object object, String response) {

    }
    class GridAdapter extends CommonAdapter {

        public GridAdapter(List mDatas, int layoutId, Context context) {
            super(mDatas, layoutId, context);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if(convertView==null){
                convertView=View.inflate(PatientActivity.this,R.layout.main_grid_item,null);
            }
            TextView textView= (TextView) ViewHolder.get(R.id.main_item, convertView);
            ImageView img= (ImageView) ViewHolder.get(R.id.grid_img,convertView);
            img.setImageResource(imgList.get(position));
            textView.setText(titleList.get(position));
            return convertView;
        }
    }
}
